import java.awt.Color;
import java.util.ArrayList;

import info.gridworld.actor.Actor;
import info.gridworld.actor.Critter;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

public class BlusterCritter extends Critter {
    private int c;

    public BlusterCritter(int cc) {
        this.c = cc;
    }

    public void darken() {
        Color primitive = this.getColor();
        double r = primitive.getRed() * 0.9;
        double g = primitive.getGreen() * 0.9;
        double b = primitive.getBlue() * 0.9;
        Color newone = new Color((int) r, (int) g, (int) b);
        this.setColor(newone);
    }

    public void brighter() {
        Color primitive = this.getColor();
        double r = primitive.getRed() * 1.1 > 255 ? 255 : primitive.getRed() * 1.1;
        double g = primitive.getGreen() * 1.1 > 255 ? 255 : primitive.getGreen() * 1.1;
        double b = primitive.getBlue() * 1.1 > 255 ? 255 : primitive.getBlue() * 1.1;
        Color newone = new Color((int) r, (int) g, (int) b);
        this.setColor(newone);
    }

    public ArrayList<Actor> getActors() {
        ArrayList<Actor> arr = new ArrayList<Actor>();
        Grid<Actor> grid = getGrid();
        for (int i = this.getLocation().getRow() - 2; i <= this.getLocation().getRow() + 2; i++) {
            for (int j = this.getLocation().getCol() - 2; j <= this.getLocation().getCol() + 2; j++) {
                if (i == this.getLocation().getRow() && j == this.getLocation().getCol())
                    continue;
                Location pos = new Location(i, j);
                if (grid.isValid(pos) && grid.get(pos) != null)
                    arr.add(grid.get(pos));
            }
        }
        return arr;
    }

    public void processActors(ArrayList<Actor> actors) {
        int cnt = 0;
        for (int i = 0; i < actors.size(); i++) {
            if (actors.get(i) instanceof Critter)
                cnt++;
        }
        if (cnt >= c)
            this.darken();
        else
            this.brighter();
    }
}
